import {
  TonTpl,
  TonOrder,
  PageData,
  putSaleDto,
  postSaleDto,
  putAdjustDto,
  putProcessDto,
  putPurchaseDto,
  postProcessDto,
  WithPasterList,
  WithStockTotal,
  postPurchaseDto,
  putSaleReturnDto,
  DisableUUid32Dto,
  postSaleReturnDto,
  getRiverTonTplDto,
  doTonSkuCreationRes,
  GateRiverTonGateway,
  GateRiverTonInterfaceWithDerive,
} from "qqlx-core";

import { ViewBase } from "@view/view-base";

export class ViewGateRiverTon extends ViewBase<TonTpl> implements GateRiverTonInterfaceWithDerive<{}> {
  private static instance: ViewGateRiverTon;
  static getInstance(options?: { isSingleton?: boolean }) {
    if (options?.isSingleton === false) {
      return new ViewGateRiverTon();
    }

    if (!this.instance) this.instance = new ViewGateRiverTon();
    return this.instance;
  }

  private constructor() {
    super();
    this.initial();
    this.insertDefaultCondition();
  }

  async getTplList(dto: getRiverTonTplDto) {
    const path = `${GateRiverTonGateway.path}/tpl/list`;
    return this.$request.getByPut<getRiverTonTplDto, PageData<WithPasterList & WithStockTotal & TonTpl>>(path, dto);
  }

  async disableOrderSync(dto: DisableUUid32Dto) {
    const path = `${GateRiverTonGateway.path}/order/disable`;
    return this.$request.delete<DisableUUid32Dto, { updated: TonOrder }>(path, dto);
  }

  async putPurchaseSkuSync(dto: putPurchaseDto) {
    const path = `${GateRiverTonGateway.path}/purchase/sku`;
    return this.$request.put<putPurchaseDto, doTonSkuCreationRes>(path, dto);
  }

  async postPurchaseSkuSync(dto: postPurchaseDto) {
    const path = `${GateRiverTonGateway.path}/purchase/sku`;
    return this.$request.post<postPurchaseDto, doTonSkuCreationRes>(path, dto);
  }

  async putAdjustSkuSync(dto: putAdjustDto) {
    const path = `${GateRiverTonGateway.path}/adjust/sku`;
    return this.$request.put<putAdjustDto, doTonSkuCreationRes>(path, dto);
  }

  async putProcessSkuSync(dto: putProcessDto) {
    const path = `${GateRiverTonGateway.path}/process/sku`;
    return this.$request.put<putProcessDto, doTonSkuCreationRes>(path, dto);
  }

  async postProcessSkuSync(dto: postProcessDto) {
    const path = `${GateRiverTonGateway.path}/process/sku`;
    return this.$request.post<postProcessDto, doTonSkuCreationRes>(path, dto);
  }

  async putSaleSkuSync(dto: putSaleDto) {
    const path = `${GateRiverTonGateway.path}/sale/sku`;
    return this.$request.put<putSaleDto, doTonSkuCreationRes>(path, dto);
  }

  async postSaleSkuSync(dto: postSaleDto) {
    const path = `${GateRiverTonGateway.path}/sale/sku`;
    return this.$request.post<postSaleDto, doTonSkuCreationRes>(path, dto);
  }

  async putSaleReturnSkuSync(dto: putSaleReturnDto) {
    const path = `${GateRiverTonGateway.path}/sale-return/sku`;
    return this.$request.put<putSaleReturnDto, doTonSkuCreationRes>(path, dto);
  }

  async postSaleReturnSkuSync(dto: postSaleReturnDto) {
    const path = `${GateRiverTonGateway.path}/sale-return/sku`;
    return this.$request.post<postSaleReturnDto, doTonSkuCreationRes>(path, dto);
  }
}
